package queue;

import java.util.Random;
import java.util.concurrent.LinkedBlockingQueue;

public class LinkedBlockingQueueDemo2 {
    private static LinkedBlockingQueue<String> bq=new LinkedBlockingQueue<>();
    public static void main(String[] args) {
        Thread t=new Thread(){
            @Override
            public void run() {
                System.out.println("消费者线程从阻塞队列中获取数据....");
                try {
                    String data=bq.take();
                    System.out.println("消费者从阻塞队列中获取的数据是:"+data);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        };
        t.start();
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        Random r=new Random();
        int number=r.nextInt(10);
        try {
            bq.put("number");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
